/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package database_objects;

import java.util.ArrayList;

/**
 *
 * @author pawel
 */
public class Book {
    
    public final static String available = "dostępna";
    public final static String notavailable = "wypozyczona";
    public final static String notavailableV = "przetrzymana";
    
    //department
    private String idOfDepartment = null;
    private String nameOfDepartment = null;
    private String bookCaseNumber = null;
    
    //edition
    private String isbn = null;
    private String nameOfEdition = null;
    private String dateOfEdition = null;
    private String title = null;
   
    //author
    private ArrayList<Author> authors = null;
    
    //book
    private String positionOnBookCase = null;
    private String idOfBook = null;
    
    private String state = available;

    public Book() {
    }
    
    public Book(String idOfDepartment, String nameOfDepartment, 
            String bookCaseNumber, String isbn, String nameOfEdition,
            String dateOfEdition, String title, ArrayList<Author> authors,
            String positionOnBookCase, String idOfBook) {
        this.idOfDepartment = idOfDepartment;
        this.nameOfDepartment = nameOfDepartment;
        this.bookCaseNumber = bookCaseNumber;
        this.isbn = isbn;
        this.nameOfEdition = nameOfEdition;
        this.dateOfEdition = dateOfEdition;
        this.title = title;
        this.authors = authors;
        this.positionOnBookCase = positionOnBookCase;
        this.idOfBook = idOfBook;
        normalizeDateOfEdition();
    }
    
    
    public Book(Department department, ArrayList<Author> authors,
            EditionBook edition, String position, String idOfBook) {
        this.idOfDepartment = department.getId();
        this.nameOfDepartment = department.getName();
        this.bookCaseNumber = department.getBookCaseNumber();
        this.isbn = edition.getIsbn();
        this.nameOfEdition = edition.getNameOfEditionHouse();
        this.dateOfEdition = edition.getDateOfPublishing();
        this.title = edition.getTitle();
        this.authors = authors;
        this.positionOnBookCase = position;
        this.idOfBook = idOfBook;
        normalizeDateOfEdition();
    }
    
    public Book(Department department, ArrayList<Author> authors,
            EditionBook edition) {
        this.idOfDepartment = department.getId();
        this.nameOfDepartment = department.getName();
        this.bookCaseNumber = department.getBookCaseNumber();
        this.isbn = edition.getIsbn();
        this.nameOfEdition = edition.getNameOfEditionHouse();
        this.dateOfEdition = edition.getDateOfPublishing();
        this.title = edition.getTitle();
        this.authors = authors;
        normalizeDateOfEdition();
    }

    public void setBookCaseNumber(String bookCaseNumber) {
        this.bookCaseNumber = bookCaseNumber;
    }

    public void setDateOfEdition(String dateOfEdition) {
       this.dateOfEdition = dateOfEdition;
       normalizeDateOfEdition();
    }
    
    private void normalizeDateOfEdition(){
        if (dateOfEdition!= null ){
            Integer index = dateOfEdition.indexOf(" ");
            if (index >= 0) {
                String substring = dateOfEdition.substring(0, index);
                this.dateOfEdition = substring;
            };
        }
    }
   

    public void setIdOfBook(String idOfBook) {
        this.idOfBook = idOfBook;
    }

    public void setIdOfDepartment(String idOfDepartment) {
        this.idOfDepartment = idOfDepartment;
    }

    public void setIsbn(String isbn) {
        this.isbn = isbn;
    }

    public void setNameOfDepartment(String nameOfDepartment) {
        this.nameOfDepartment = nameOfDepartment;
    }

    public void setNameOfEdition(String nameOfEdition) {
        this.nameOfEdition = nameOfEdition;
    }

    public void setNameOfauthor(ArrayList<Author> nameOfauthor) {
        this.authors = nameOfauthor;
    }

    public void setPositionOnBookCase(String positionOnBookCase) {
        this.positionOnBookCase = positionOnBookCase;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the idOfDepartment
     */
    public String getIdOfDepartment() {
        return idOfDepartment;
    }

    /**
     * @return the nameOfDepartment
     */
    public String getNameOfDepartment() {
        return nameOfDepartment;
    }

    /**
     * @return the bookCaseNumber
     */
    public String getBookCaseNumber() {
        return bookCaseNumber;
    }

    /**
     * @return the isbn
     */
    public String getIsbn() {
        return isbn;
    }

    /**
     * @return the nameOfEdition
     */
    public String getNameOfEdition() {
        return nameOfEdition;
    }

    /**
     * @return the dateOfEdition
     */
    public String getDateOfEdition() {
        return dateOfEdition;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @return the authors
     */
    public ArrayList<Author> getAuthors() {
        return authors;
    }

    /**
     * @return the positionOnBookCase
     */
    public String getPositionOnBookCase() {
        return positionOnBookCase;
    }

    /**
     * @return the idOfBook
     */
    public String getIdOfBook() {
        return idOfBook;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getState() {
        return state;
    }

    
    
    
    
    
    
}
